use "data/individual/gss7221_r1a.dta", clear 
*****Confidence variables
/*
*Recode all missings to .
foreach conrecode of varlist con* {
                recode `conrecode' (.d .i .n=.)
        }
*/

*Environmental Spending
egen drop_spend_env = rowtotal(natenvir natenviy natenviz), m

recode drop_spend_env ///
	(3 2=0 "Not Too Little") ///
	(1=1 "Too Little"), ///
	gen(spend_env)
	
lab var spend_env "Environmental Spending"	


*Confidence in Science
recode consci ///
	(3 2=0 "Not a great deal") ///
	(1=1 "A great deal") ///
	 (.d .i .n .s=.), ///
	gen(sci_con)
	
la var sci_con "Confidence in scientific community"


***Recode other variables
*Party ID
drop partyid3

recode partyid ///
	(0 1 2=3 "Dem") ///
	(3=2 "Independent") ///
	(4 5 6 =1 "GOP") ///
	(else=.), ///
	gen(partyid3)
lab var partyid3 "Party Preference, GOP->Dem., 3 categories"

*Political Ideology
recode polviewx ///
	(1=1) ///
	(2 3=2) ///
	(4=3) ///
	(5=4) ///
	(6=5) ///
	(7 8 =6) ///
	(9 10 = 7), ///
	gen(polid1)
	
egen polidALL = rowtotal(polid1 polviews)

recode polidALL ///
	(0=.) ///
	(1=7 "Ext. liberal") ///
	(2=6 "liberal") ///
	(3=5 "somewhat liberal") ///
	(4=4 "moderate") ///
	(5=3 "Somewhat conservative") ///
	(6=2 "conservative") ///
	(7=1 "Ext. conservative"), ///
	gen(polid7)
lab var polid7 "Political Ideology, con->lib, 7 categories"

***Control variables
*Education
lab var educ "Education, in years"

recode degree ///
	(0=1 "<HS") ///
	(1=2 "HS Graduate") ///
	(2=3 "Some College") ///
	(3 4 =4 "College Graduate") ///
	(else=.), ///
	gen(education)
lab var education "Education"

//Race
gen racethn=race
lab var racethn "Racial Identity"
lab def racethn 1 "White" 2 "Black" 3 "Other"
lab val racethn racethn

*add in 2021
replace racethn=1 if raceacs1==1&year==2021
replace racethn=2 if raceacs2==1&year==2021
replace racethn=3 if raceacs1==0&raceacs2==0&year==2021

drop race

rename racethn race
*Gender
recode sex ///
	(1=0 "Male") ///
	(2=1 "Female") ///
	(else=.), ///
	gen(female)
lab var female "Female"

*Recode age
gen rage=age
lab var rage "Age"

*recode cohort
rename cohort cohort_old
recode cohort_old ///
	(1880/1904=1 "<1904") ///
	(1905/1909=2 "1905-1909") ///
	(1910/1914=3 "1910-1914") ///
	(1915/1919=4 "1915-1919") ///	
	(1920/1924=5 "1920-1924") ///
	(1925/1929=6 "1925-1929") ///	
	(1930/1934=7 "1930-1934") ///
	(1935/1939=8 "1935-1939") ///
	(1940/1944=9 "1940-1944") ///
	(1945/1949=10 "1945-1949") ///
	(1950/1954=11 "1950-1954") ///
	(1955/1959=12 "1955-1959") ///
	(1960/1964=13 "1960-1964") ///
	(1965/1969=14 "1965-1969") ///
	(1970/1974=15 "1970-1974") ///
	(1975/1979=16 "1975-1979") ///
	(1980/1984=17 "1980-1984") ///
	(1985/1989=18 "1985-1989") ///
	(1990/1994=19 "1990-1994") ///
	(1995/2018=20 ">1995") ///
	(9999=.), ///
	gen(cohort) l(cohortcat)
la var cohort "Cohort"

*Rural/urban
recode xnorcsiz ///
	(1/6=0 "non-Rural") ///
	(7/10=1 "Rural"), ///
	gen(rural)
lab var rural "Rural Residence"

*Southern Residence
recode region ///
	(5/7=1 "Southern") ///
	(1/4=0 "non-Southern") ///
	(8/9=0 "non-Southern") ///
	(else=.), ///
	gen(south)
lab var south "Southern State"	


gen data=1
la def data 1 "GSS" 2 "Pew" 3 "Gallup"
la val data data

keep ///
	data year cohort id ///
	sci_con  spend_env ///
	partyid3 education ///
	age female race south 
	
save "data/individual/GSS_1972_2021_recode.dta", replace




